package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * @author moningxi
 */
@Mapper
public interface ShoppingCartMapper {
    /**
     * 添加购物车
     */
    @Insert("insert into shopping_cart(name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount, create_time) " +
            "values (#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    void add(ShoppingCart shoppingCart);

    /**
     * 更据用户id和菜品信息
     */
    List<ShoppingCart> queryByUserAndDishInfo(ShoppingCart shoppingCart);

    /**
     * 更新购物车
     */
    void update(ShoppingCart dbCart);

    /**
     * 清空购物车
     */
    @Delete("delete from shopping_cart where user_id=#{userId}")
    void clean(Long userId);

    /**
     * 更据id删除
     */
    @Delete("delete from shopping_cart where id=#{id}")
    void deleteById(Long id);

    /**
     * 批量加入购物车
     */
    void insertBatch(List<ShoppingCart> shoppingCarts);
}
